Skip to content

Comments

added virtual machine#8

Open
Kimislazuli wants to merge 2 commits intomainfrom
virtualmachine
Open

added virtual machine#8
Kimislazuli wants to merge 2 commits intomainfrom
virtualmachine

Conversation

@Kimislazuli
Copy link
Collaborator

No description provided.

@@ -0,0 +1,27 @@
package ru.jengine.virtualmachine.commands;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Предлагаю начать писать тесты :) По сути весь данный пакет должен перекочевать в тестовую структуру, за исключением интерфейса Command

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Context (Script)
  • VM (+ перенести имеющиеся команды в тесты)


public class ScriptContext implements CommandContext {
private final VMStack stack = new VMStack(1024);
private final List<Object> storage;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Есть мысль назвать данное хранилище регистрами) Вообще мы можем создать отдельный объект, который будет представлять эту абстракцию регистров. Сейчас у нас лист объектов, что является достаточно ненадёжным. Хотелось бы, наверное иметь отдельный объект ScriptRegisters с таким контрактом:

public interface ScriptRegisters {
    @Nullable
    Object getRegister(String registerName);
    void setRegister(String registerName, Object registerValue);
}

Возможно будет иметь смысл регистры ограничивать (чтобы мы могли поддерживать только конкретные регистры, типа иметь список разрешённых registerName, но это пока оставим на будущее)


public void push(Object element) {
if (stack.size() == stackSize) {
throw new StackOverflowError("VM's stack has overflowed.");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Тут давай кидать тоже VirtualMachineException. throw new VirtualMachineException(VM's stack has overflowed! Command push is unavailable);

}

@Override
public int execute(CommandContext context) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Давай, наверное, унаследуем VirtualMachineException от Exception и тут сделаем throws VirtualMachineException.
Соответственно во всех метода контекста, где может упасть ошибка виртуальной машины - тоже добавим throws

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants